package com.softer.chengxin.excel.controller;

import com.softer.chengxin.common.domin.Common;
import com.softer.chengxin.common.domin.ManagerPageResult;
import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.excel.domin.ExportExcel;
import com.softer.chengxin.excel.service.ReportService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author Gong Zhiyang
 * @date 2019/2/25
 */
@RestController
@RequestMapping("/api/excel")
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 统计全部地区的报表统计
     * （市账号登陆，显示各个区的信息；区账号登陆，显示各个街道信息）
     *
     * @param exportExcel 统计报表查询实体
     * @param page        页面信息
     * @param session     缓存
     * @return 结果集
     */
    @PostMapping("/getReport")
    public ManagerPageResult getReport(ExportExcel exportExcel, Page page, HttpSession session) {
        String loginName = (String) session.getAttribute("loginName");
        if (StringUtils.isBlank(loginName)) {
            return new ManagerPageResult();
        }
        Integer district = exportExcel.getDistrict();
        if (Common.ZERO.equals(String.valueOf(district))) {
            exportExcel.setDistrict(null);
        }
        return reportService.getReport(exportExcel, page, loginName);
    }
}
